import time

from common.base import Base, get_driver
from selenium.webdriver.common.by import By


class IndexPage(Base):
    def font_username_text(self):
        return self.get_text((By.XPATH, '//font[@class="f4_b"]'))

    def a_logout(self):
        self.click((By.LINK_TEXT, '退出'))

    def a_login(self):
        self.click((By.PARTIAL_LINK_TEXT, '请登录'))

    def a_register(self):
        self.click((By.LINK_TEXT, '免费注册'))

    # 选择商品
    def click_shop1(self):
        self.click((By.CLASS_NAME, 'goodsimg'))

    def click_shop2(self):
        self.click((By.XPATH, '//a[@class="goodsItem"][3]//img'))

    # 登录账号
    def login_shop(self):
        self.click((By.LINK_TEXT, '请登录'))
        self.send_keys((By.NAME, 'username'), 'root123456')
        self.send_keys((By.NAME, 'password'), 'root123456')
        self.click((By.NAME, 'submit'))

    # 进入用户中心收货地址页面
    def user_address(self):
        self.click((By.LINK_TEXT, '用户中心'))
        self.click((By.LINK_TEXT, '收货地址'))

if __name__ == '__main__':
    # 创建driver
    driver = get_driver()
    driver.get('http://localhost:8080/ecshop/index.php')

    index = IndexPage(driver)
    index.login_shop()
    index.user_address()

    # index.click_shop2()
